class CD_IUP

inherit
	CANVAS_DRAW
	CD_CANVAS_SIMULATE
	CD_CANVAS_INITIALIZATION
	CD_CANVAS_CONTROL
	CD_CANVAS_COORDINATE_SYSTEM
	CD_CANVAS_WORLD_COORDINATES
	CD_CANVAS_GENERAL_ATTRIBUTES
	CD_CLIPPING
	CD_PRIMITIVES_MARKS
	CD_LINES
	CD_POLYGONS_BEZIER_REGIONS
	CD_COMPLEX_CLIPPING_REGIONS
	CD_FILLED_AREAS
	CD_TEXT
	CD_VECTOR_TEXT
	CD_CLIENT_IMAGES

create {IUP_CANVAS}
   create_with_front_cd_canvas

create {IUP_CONTROLS}
   create_with_cd_canvas

create {IUP_CANVAS, IUP_CONTROLS}
   create_default
	
create {ANY}
   create_with_canvas,
   create_double_buffer_with_canvas,
   create_double_buffer_rgb_with_canvas

feature {IUP_CANVAS}

	create_with_front_cd_canvas (p: POINTER)
		do
			cnvs := p
		end

feature {IUP_CONTROLS}

	create_with_cd_canvas (wgt: IUP_CANVAS; p: POINTER)
		do
			cnvs := p
			wgt.set_cd_canvas(Current)

			initialize_modes
			initialize_colors
		end

feature {IUP_CANVAS, IUP_CONTROLS}

	create_default
		do
		end
	
feature {ANY}

	create_with_canvas (wgt: IUP_CANVAS)
		do
			cnvs := int_create_canvas(int_cd_context_iup, wgt.widget)
			wgt.set_cd_canvas(Current)

			initialize_modes
			initialize_colors
		end

	create_double_buffer_with_canvas (wgt: IUP_CANVAS)
		do
			cnvs := int_create_canvas(int_cd_context_iup_double_buffer, wgt.widget)
			wgt.set_back_and_front_cd_canvas(Current)

			initialize_modes
			initialize_colors
		end

	create_double_buffer_rgb_with_canvas (wgt: IUP_CANVAS)
		do
			cnvs := int_create_canvas(int_cd_context_iup_double_buffer_rgb,
                                   wgt.widget)
			wgt.set_back_and_front_cd_canvas(Current)

			initialize_modes
			initialize_colors
		end

feature {NONE}

	-- Internals
	int_create_canvas (context, data: POINTER): POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdCreateCanvas ($context, $data);"
      end

	int_cd_context_iup: POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdContextIup();"
      end

	int_cd_context_iup_double_buffer: POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdContextIupDBuffer();"
      end

	int_cd_context_iup_double_buffer_rgb: POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdContextIupDBufferRGB();"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
